﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;

public class Skills : MonoBehaviour 
{
	public int combatLevel = 1;


	public List<Skill> skills;

	void Awake()
	{
		Clean ();
		foreach (Skill skill in skills)
		{
			skill.Reset ();
		}
	}

	void OnPhotonSerializeView(PhotonStream stream,PhotonMessageInfo info)
	{
		if (stream.isWriting)
		{	
			stream.SendNext (combatLevel);
		}else if (stream.isReading)
		{	
			combatLevel = (int)stream.ReceiveNext ();
		}
	}
	[PunRPC]
	public void GainXP(int amount, int name)
	{
		foreach (Skill skill in skills)
		{
			if (skill.skillName == name)
			{
				skill.GainXP (amount);
			}
		}
	}

	void Clean()
	{
		skills = skills.GroupBy (p => p.skillName).Select (g => g.First ()).ToList ();
	}
}
